/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-19 10:21:45
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-19 10:50:12
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/loading.dart';
import 'package:flutter_data_center/controller/warning_controller.dart';
import 'package:flutter_data_center/model/warning/warning_model.dart';
import 'package:get/get.dart';

import 'warning_item.dart';

class WarningList extends StatelessWidget {
  const WarningList({Key key, this.onTap}) : super(key: key);
  final ValueChanged<WarningModel> onTap;

  @override
  Widget build(BuildContext context) => GetBuilder<WarningController>(
        builder: (_controller) => _controller.warnings.length > 0
            ? ListView.builder(
                physics: BouncingScrollPhysics(),
                itemCount: _controller.warnings.length,
                itemBuilder: (context, index) => GestureDetector(
                  onTap: () => onTap(_controller.warnings[index]),
                  child: WarningItem(
                    warning: _controller.warnings[index],
                  ),
                ),
              )
            : Loading(),
      );
}
